import 'package:im_app/im/socket/ImWebSocketIsolate.dart';
import 'package:im_app/im/socket/ImWebSocketIsolate2.dart';
import 'package:im_app/im/socket/ImWebSocketable.dart';
import 'package:im_app/im/util/DbUtil.dart';
import 'package:im_app/im/util/ImSingleton.dart';
import 'package:sqflite/sqflite.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';

class BaseImTest {
  static Future<ImWebSocketable?> initWebSocket() async {
    bool isWebSocket = ImSingleton.getInstance()?.isWebSocketInstance??false;
    if (isWebSocket == false) {
      ImWebSocketable imWebSocket = new ImWebSocketIsolate('ws://127.0.0.1:9290/imWebsocket');
      await imWebSocket.start();
      ImSingleton.getInstance()?.imWebSocket = imWebSocket;
    }
    return ImSingleton.getInstance()?.imWebSocket;
  }

  static Future<Database> initDb() async {
    sqfliteFfiInit();
    databaseFactory = databaseFactoryFfi;
    Database database = await DbUtil.connect("imtest.db");
    return database;
  }
}